package com.satchi.struts.action.customeraction;

import java.io.PrintWriter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.satchi.service.GetCustomerService;
import com.satchi.struts.ActionHelper;

public class RefreshCustomer extends Action {
	@Override
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		GetCustomerService customerServ = new GetCustomerService();
		
		String message = null;
		if(ActionHelper.IsEmpty(request.getParameter("status")))
			message = customerServ.RefreshCustomers(!ActionHelper.IsEmpty(request.getParameter("byTitle")));
		else
			message = customerServ.RefreshCustomersEnable(!ActionHelper.IsEmpty(request.getParameter("byTitle")));
			
		PrintWriter writer = response.getWriter();
		writer.write(message);
		writer.flush();
		writer.close();
		
		return mapping.findForward(null);
	}
}
